home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / VERTSEL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  7.5 KB  |  352 lines

  1.  
  2. #include "stdafx.h"
  3. #include "qe3.h"
  4. #include "winding.h"
  5.  
  6. #define NEWEDGESEL 1
  7.  
  8.  
  9. int    FindPoint (vec3_t point)
  10. {
  11.     int        i, j;
  12.  
  13.     for (i=0 ; i<g_qeglobals.d_numpoints ; i++)
  14.     {
  15.         for (j=0 ; j<3 ; j++)
  16.             if (fabs(point[j] - g_qeglobals.d_points[i][j]) > 0.1)
  17.                 break;
  18.         if (j == 3)
  19.             return i;
  20.     }
  21.  
  22.     VectorCopy (point, g_qeglobals.d_points[g_qeglobals.d_numpoints]);
  23.   if (g_qeglobals.d_numpoints < MAX_POINTS-1)
  24.   {
  25.       g_qeglobals.d_numpoints++;
  26.   }
  27.  
  28.     return g_qeglobals.d_numpoints-1;
  29. }
  30.  
  31. int FindEdge (int p1, int p2, face_t *f)
  32. {
  33.     int        i;
  34.  
  35.     for (i=0 ; i<g_qeglobals.d_numedges ; i++)
  36.         if (g_qeglobals.d_edges[i].p1 == p2 && g_qeglobals.d_edges[i].p2 == p1)
  37.         {
  38.             g_qeglobals.d_edges[i].f2 = f;
  39.             return i;
  40.         }
  41.  
  42.     g_qeglobals.d_edges[g_qeglobals.d_numedges].p1 = p1;
  43.     g_qeglobals.d_edges[g_qeglobals.d_numedges].p2 = p2;
  44.     g_qeglobals.d_edges[g_qeglobals.d_numedges].f1 = f;
  45.  
  46.   if (g_qeglobals.d_numedges < MAX_EDGES-1)
  47.   {
  48.       g_qeglobals.d_numedges++;
  49.   }
  50.  
  51.     return g_qeglobals.d_numedges-1;
  52. }
  53.  
  54. #ifdef NEWEDGESEL
  55. void MakeFace (brush_t* b, face_t *f)
  56. #else
  57. void MakeFace (face_t *f)
  58. #endif
  59. {
  60.     winding_t    *w;
  61.     int            i;
  62.     int            pnum[128];
  63.  
  64. #ifdef NEWEDGESEL
  65.     w = Brush_MakeFaceWinding (b, f);
  66. #else
  67.     w = Brush_MakeFaceWinding (selected_brushes.next, f);
  68. #endif
  69.     if (!w)
  70.         return;
  71.     for (i=0 ; i<w->numpoints ; i++)
  72.         pnum[i] = FindPoint (w->points[i]);
  73.     for (i=0 ; i<w->numpoints ; i++)
  74.         FindEdge (pnum[i], pnum[(i+1)%w->numpoints], f);
  75.  
  76.     free (w);
  77. }
  78.  
  79. void SetupVertexSelection (void)
  80. {
  81.     face_t    *f;
  82.     brush_t *b;
  83.  
  84.     g_qeglobals.d_numpoints = 0;
  85.     g_qeglobals.d_numedges = 0;
  86.  
  87. #ifdef NEWEDGESEL
  88.     for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  89.   {
  90.       for (f=b->brush_faces ; f ; f=f->next)
  91.           MakeFace (b,f);
  92.   }
  93. #else
  94.     if (!QE_SingleBrush())
  95.         return;
  96.  
  97.   b = selected_brushes.next;
  98.   for (f=b->brush_faces ; f ; f=f->next)
  99.     MakeFace (b,f);
  100. #endif
  101.  
  102. }
  103.  
  104.  
  105. #ifdef NEWEDGESEL
  106. void SelectFaceEdge (brush_t* b, face_t *f, int p1, int p2)
  107. #else
  108. void SelectFaceEdge (face_t *f, int p1, int p2)
  109. #endif
  110. {
  111.     winding_t    *w;
  112.     int            i, j, k;
  113.     int            pnum[128];
  114.  
  115. #ifdef NEWEDGESEL
  116.     w = Brush_MakeFaceWinding (b, f);
  117. #else
  118.     w = Brush_MakeFaceWinding (selected_brushes.next, f);
  119. #endif
  120.     if (!w)
  121.         return;
  122.     for (i=0 ; i<w->numpoints ; i++)
  123.         pnum[i] = FindPoint (w->points[i]);
  124.  
  125.   for (i=0 ; i<w->numpoints ; i++)
  126.         if (pnum[i] == p1 && pnum[(i+1)%w->numpoints] == p2)
  127.         {
  128.             VectorCopy (g_qeglobals.d_points[pnum[i]], f->planepts[0]);
  129.             VectorCopy (g_qeglobals.d_points[pnum[(i+1)%w->numpoints]], f->planepts[1]);
  130.             VectorCopy (g_qeglobals.d_points[pnum[(i+2)%w->numpoints]], f->planepts[2]);
  131.             for (j=0 ; j<3 ; j++)
  132.             {
  133.                 for (k=0 ; k<3 ; k++)
  134.                 {
  135.                     f->planepts[j][k] = floor(f->planepts[j][k]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize;
  136.                 }
  137.             }
  138.  
  139.             AddPlanept (f->planepts[0]);
  140.             AddPlanept (f->planepts[1]);
  141.             break;
  142.         }
  143.  
  144.     if (i == w->numpoints)
  145.         Sys_Printf ("SelectFaceEdge: failed\n");
  146.     free (w);
  147. }
  148.  
  149.  
  150. void SelectVertex (int p1)
  151. {
  152.     brush_t        *b;
  153.     winding_t    *w;
  154.     int            i, j, k;
  155.     face_t        *f;
  156.  
  157. #ifdef NEWEDGESEL
  158.     for (b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  159.   {
  160.       for (f=b->brush_faces ; f ; f=f->next)
  161.       {
  162.           w =  Brush_MakeFaceWinding (b, f);
  163.           if (!w)
  164.               continue;
  165.           for (i=0 ; i<w->numpoints ; i++)
  166.           {
  167.               if (FindPoint (w->points[i]) == p1)
  168.               {
  169.                   VectorCopy (w->points[(i+w->numpoints-1)%w->numpoints], f->planepts[0]);
  170.                   VectorCopy (w->points[i], f->planepts[1]);
  171.                   VectorCopy (w->points[(i+1)%w->numpoints], f->planepts[2]);
  172.                 for (j=0 ; j<3 ; j++)
  173.           {
  174.                     for (k=0 ; k<3 ; k++)
  175.             {
  176.                         ;//f->planepts[j][k] = floor(f->planepts[j][k]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize;
  177.             } 
  178.           }
  179.  
  180.                 AddPlanept (f->planepts[1]);
  181.           //MessageBeep(-1);
  182.  
  183.                 break;
  184.         }
  185.           }
  186.           free (w);
  187.       }
  188.   }
  189. #else
  190.     b = selected_brushes.next;
  191.     for (f=b->brush_faces ; f ; f=f->next)
  192.     {
  193.         w =  Brush_MakeFaceWinding (b, f);
  194.         if (!w)
  195.             continue;
  196.         for (i=0 ; i<w->numpoints ; i++)
  197.         {
  198.             if (FindPoint (w->points[i]) == p1)
  199.             {
  200.                 VectorCopy (w->points[(i+w->numpoints-1)%w->numpoints], f->planepts[0]);
  201.                 VectorCopy (w->points[i], f->planepts[1]);
  202.                 VectorCopy (w->points[(i+1)%w->numpoints], f->planepts[2]);
  203.               for (j=0 ; j<3 ; j++)
  204.         {
  205.                   for (k=0 ; k<3 ; k++)
  206.           {
  207.                       ;//f->planepts[j][k] = floor(f->planepts[j][k]/g_qeglobals.d_gridsize+0.5)*g_qeglobals.d_gridsize;
  208.           } 
  209.         }
  210.  
  211.               AddPlanept (f->planepts[1]);
  212.         //MessageBeep(-1);
  213.  
  214.               break;
  215.       }
  216.         }
  217.         free (w);
  218.     }
  219. #endif
  220. }
  221.  
  222. void SelectEdgeByRay (vec3_t org, vec3_t dir)
  223. {
  224.     int        i, j, besti;
  225.     float    d, bestd;
  226.     vec3_t    mid, temp;
  227.     pedge_t    *e;
  228.  
  229.     // find the edge closest to the ray
  230.     besti = -1;
  231.     bestd = 8;
  232.  
  233.     for (i=0 ; i<g_qeglobals.d_numedges ; i++)
  234.     {
  235.         for (j=0 ; j<3 ; j++)
  236.             mid[j] = 0.5*(g_qeglobals.d_points[g_qeglobals.d_edges[i].p1][j] + g_qeglobals.d_points[g_qeglobals.d_edges[i].p2][j]);
  237.  
  238.         VectorSubtract (mid, org, temp);
  239.         d = DotProduct (temp, dir);
  240.         VectorMA (org, d, dir, temp);
  241.         VectorSubtract (mid, temp, temp);
  242.         d = VectorLength (temp);
  243.         if (d < bestd)
  244.         {
  245.             bestd = d;
  246.             besti = i;
  247.         }
  248.     }
  249.  
  250.     if (besti == -1)
  251.     {
  252.         Sys_Printf ("Click didn't hit an edge\n");
  253.         return;
  254.     }
  255.     Sys_Printf ("hit edge\n");
  256.  
  257.     // make the two faces that border the edge use the two edge points
  258.     // as primary drag points
  259.     g_qeglobals.d_num_move_points = 0;
  260.     e = &g_qeglobals.d_edges[besti];
  261. #ifdef NEWEDGESEL
  262.     for (brush_t* b=selected_brushes.next ; b != &selected_brushes ; b=b->next)
  263.   {
  264.     SelectFaceEdge (b, e->f1, e->p1, e->p2);
  265.       SelectFaceEdge (b, e->f2, e->p2, e->p1);
  266.   }
  267. #else
  268.   SelectFaceEdge (e->f1, e->p1, e->p2);
  269.     SelectFaceEdge (e->f2, e->p2, e->p1);
  270. #endif
  271.  
  272.  
  273. }
  274.  
  275. void SelectVertexByRay (vec3_t org, vec3_t dir)
  276. {
  277.     int        i, besti;
  278.     float    d, bestd;
  279.     vec3_t    temp;
  280.  
  281.     // find the point closest to the ray
  282.     besti = -1;
  283.     bestd = 8;
  284.  
  285.     for (i=0 ; i<g_qeglobals.d_numpoints ; i++)
  286.     {
  287.         VectorSubtract (g_qeglobals.d_points[i], org, temp);
  288.         d = DotProduct (temp, dir);
  289.         VectorMA (org, d, dir, temp);
  290.         VectorSubtract (g_qeglobals.d_points[i], temp, temp);
  291.         d = VectorLength (temp);
  292.         if (d < bestd)
  293.         {
  294.             bestd = d;
  295.             besti = i;
  296.         }
  297.     }
  298.  
  299.     if (besti == -1)
  300.     {
  301.         Sys_Printf ("Click didn't hit a vertex\n");
  302.         return;
  303.     }
  304.     Sys_Printf ("hit vertex\n");
  305.     g_qeglobals.d_move_points[g_qeglobals.d_num_move_points++] = g_qeglobals.d_points[besti];
  306.     //SelectVertex (besti);
  307. }
  308.  
  309.  
  310.  
  311. extern void AddPatchMovePoint(vec3_t v, bool bMulti, bool bFull);
  312. void SelectCurvePointByRay (vec3_t org, vec3_t dir, int buttons)
  313. {
  314.     int        i, besti;
  315.     float    d, bestd;
  316.     vec3_t    temp;
  317.  
  318.     // find the point closest to the ray
  319.     besti = -1;
  320.     bestd = 8;
  321.  
  322.     for (i=0 ; i<g_qeglobals.d_numpoints ; i++)
  323.     {
  324.         VectorSubtract (g_qeglobals.d_points[i], org, temp);
  325.         d = DotProduct (temp, dir);
  326.         VectorMA (org, d, dir, temp);
  327.         VectorSubtract (g_qeglobals.d_points[i], temp, temp);
  328.         d = VectorLength (temp);
  329.         if (d <= bestd)
  330.         {
  331.             bestd = d;
  332.             besti = i;
  333.         }
  334.     }
  335.  
  336.     if (besti == -1)
  337.     {
  338.     if (g_pParentWnd->ActiveXY()->AreaSelectOK())
  339.     {
  340.       g_qeglobals.d_select_mode = sel_area;
  341.       VectorCopy(org, g_qeglobals.d_vAreaTL);
  342.       VectorCopy(org, g_qeglobals.d_vAreaBR);
  343.     }
  344.         return;
  345.     }
  346.     //Sys_Printf ("hit vertex\n");
  347.   AddPatchMovePoint(g_qeglobals.d_points[besti], buttons & MK_CONTROL, buttons & MK_SHIFT);
  348. }
  349.  
  350.  
  351.  
  352.